// pages/my/myRecord/myRecord.js
const app = getApp();
var time = require("../../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    winWidth: 0,
    winHeight: 0,
    currentTab: 0,
    autoplay: false,
    indicatorDots: false,
    circular:false,
    topNum: 0,
    currentPage:1,
    goods:[],
    lost:[],
    job:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;

    /** 
     * 获取系统信息 
     */
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight,
        });
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.goodsRecordShow();
    this.lostRecordShow();
    this.parttimeRecordShow();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /**
   * 请求二手商品记录
   */
  goodsRecordShow(){
    var that = this;
    wx.request({
      url: app.globalData.urlPath + "getGoodsListByUserId.action",
      data: {
        rdSession: app.globalData.rdSession,
        currentPage: that.data.currentPage,
        pageSize: 2,
      },
      method: "GET",
      success(res) {
        for (var i = 0; i < res.data.data.length; i++) {
          res.data.data[i]["createTime"] = time.formatTime(res.data.data[i]["createTime"] / 1000, 'Y/M/D');
          res.data.data[i]["images"] = app.globalData.imgPath + res.data.data[i]["images"].split(";")[0];
        }
        console.log(res.data);
        that.setData({
          goods: res.data.data,
        })
      },

      fail(res){}
    })
  },

  /**
   * 请求发布的失物招领记录
   */
  lostRecordShow:function(){
    var that = this;
    wx.request({
      url: app.globalData.urlPath + "getLostFoundListByUserId.action",
      data: {
        rdSession: app.globalData.rdSession,
        pageSize: 5,
      },
      method: "GET",
      success(res) {
        for (var i = 0; i < res.data.data.length; i++) {
          res.data.data[i]["createTime"] = time.formatTime(res.data.data[i]["createTime"] / 1000, 'Y/M/D');
        }
        console.log(res.data);
        that.setData({
          lost: res.data.data,
        })
      },
    })
  },
/**
 * 请求发布的兼职记录
 */
parttimeRecordShow:function(){
  var that = this;
  wx.request({
    url: app.globalData.urlPath + "getPartTimeListByUserId.action",
    data: {
      rdSession: app.globalData.rdSession,
      pageSize: 5,
    },
    method: "GET",
    success(res) {
      for (var i = 0; i < res.data.data.length; i++) {
        res.data.data[i]["createTime"] = time.formatTime(res.data.data[i]["createTime"] / 1000, 'Y/M/D');
      }
      console.log(res.data);
      that.setData({
        job: res.data.data,
      })
    },
  })
},
  /**
   * 滑动改变swiper-item
   */
  bindChange: function(e) {
    var that = this;
    if(e.detail.source=="touch")
      that.setData({
        currentTab:e.detail.current,
        topNum:0,
      });
  },

  /**
   * 点击改变swiper-item
   */
  switchNav: function(e){
    var that = this;

    if(that.data.currentTab==e.target.dataset.current){
      return false;
    }else{
      that.setData({
        currentTab:e.target.dataset.current,
        topNum:0,
      })
    }
  },

  // 获取滚动条当前位置
  scrollUpper: function (e) {
    var that = this;
    console.log(e)
    if (e.detail.scrollTop > 100) {
      that.setData({
        floorstatus: true
      });
    } else {
      that.setData({
        floorstatus: false
      });
    }
  },

  //回到顶部
  goTop: function (e) {
    var that = this;
    that.setData({
      topNum: 0,
    });
  },

  /**
   * 转到二手商品详细页面
   */
  toGoodsDetail:function(e){
    var that = this;
    var goodsId = parseInt(e.currentTarget.dataset.goodsid)
    wx.navigateTo({
      url: '/pages/goods/goodsDetail/goodsDetail?goodsId='+goodsId,
    })
    console.log(goodsId);
  },

  /**
   * 转到失物招领详情页面
   */
  toLostDetail:function(e){
    var that = this;
    var lostId = parseInt(e.currentTarget.dataset.lostid);
    wx.navigateTo({
      url: '/pages/lost/lostDetail/lostDetail?lostId=' + lostId,
    })
  },

  /**
   * 转到兼职详情页面
   */
  toJobDetail:function(e){
    var that = this;
    var jobId = parseInt(e.currentTarget.dataset.jobid);
    wx.navigateTo({
      url: '/pages/parttime/detail/detail?id=' + jobId,
    })
  }
})